package com.mycompany.project.client.chee;

import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image;

/**
 * This class will deal with the map portion of the application.
 *
 * @author LeeNou,Jack,Timothy Duch
 *
 */
public final class MapGUI {
    /**
     * This represents the number of rows for the grid.
     */
    public static final int ROW = 50;
    /**
     * This represents the number of columns for the grid.
     */
    public static final int COL = 50;
    /**
     * This is the grid at the core of the MapGUI.
     */
    private static final Grid MAPGRID = new Grid(ROW, COL);
    /**
     * This number is used for cellpadding, for formatting purposes.
     */
    private static final int CELLPADDING = 4;
    /**
     * This number is used for formatting of the grid.
     */
    private static final int FORMATNUMBER = 10;

    /**
     * This method initializes the map.
     */
    public static void initMap() {
        MAPGRID.clear();
        MAPGRID.setBorderWidth(2);
        MAPGRID.setCellPadding(CELLPADDING);
        MAPGRID.setStyleName("bgMap");
        for (int i = 0; i < ROW; i++) {
            MAPGRID.setWidget(i, 0, new HTML("<center><font color=\"white\">"
                    + i + "</center></font>"));
        }
        for (int j = 0; j < COL; j++) {
            if (j < FORMATNUMBER) {
                MAPGRID.setWidget(0, j, new HTML(
                        "<font color=\"white\"><center>_" + j
                                + "</center></font>"));
            } else {
                MAPGRID.setWidget(0, j, new HTML(
                        "<font color=\"white\"><center>" + j
                                + "</center></font>"));
            }
        }
        // display the modules on map if there's any
        for (int i = 0; i < ModuleList.getMlist().size(); i++) {
            for (int j = 0; j < ModuleList.getMlist().get(i).size(); j++) {
            	//Image img = new Image(Module.getModuleImage(i));
            	//img.setTitle(ModuleList.getMlist().get(i).get(j).getString());
            	ModuleList.getMlist().get(i).get(j).setTitle(ModuleList.getMlist().get(i).get(j).getString());
                MAPGRID.setWidget(
                        ModuleList.getMlist().get(i).get(j).getPositionY(),
                        ModuleList.getMlist().get(i).get(j).getPositionX(),ModuleList.getMlist().get(i).get(j));
            }
        }
    }

    /**
     *
     * @return the map grid
     */
    public static Grid getGrid() {
        return MAPGRID;
    }

    /**
     * Constructor for the class.
     */
    private MapGUI() {
        initMap();
    }
}
